package cn.handong.tool.Java文件操作.txt;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class House implements Comparable<House>{
    private String name;
    private Integer floorNum;
    private Integer roomNum;
    private String unitPrice;
    private Integer price;
    private String structureArea;

    /**
     * o.price - this.price   //降序
     * 排序规则：
     * 1、5楼及以上：楼层优先，东边第二，价格第三
     * 2、4楼及一下：
     */
    @Override
    public int compareTo(House o) {
        if (Objects.equals(o.floorNum, this.floorNum)){
            if (Objects.equals(o.roomNum, this.roomNum)){
                return - (o.price - this.price); //先看便宜的    升序
            }else {
                return this.roomNum - o.roomNum; //先看01   升序
            }
        }else {
            return o.floorNum - this.floorNum;  //先看高楼层   降序
        }
    }

    public House(String lineTxt){
        // 每行数据以逗号分隔
        String[] names = lineTxt.split("-");
        name = lineTxt;
        price = Integer.parseInt(names[2]);
        roomNum = Integer.parseInt(names[1].substring(names[1].length() - 1));
        floorNum = Integer.parseInt(names[1].substring(0,names[1].length() - 2));
    }
}
